home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FBAAppleEvents.c
-
- Contains:
-
- Written by: Greg Sutton
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/21/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- // This has been modfied a bit by me -Shawn Platkus
-
- #include "MyAppleEvents.h"
-
- #include "MyIncludes.h"
-
- #include <Events.h>
- #include <Errors.h>
- #include <AERegistry.h>
- #include <Gestalt.h>
- #include <Resources.h>
-
- // prototypes
- static pascal OSErr HandleOpenApplication( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon );
- static pascal OSErr HandleQuitApplication( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon );
- static pascal OSErr HandleOpenDocuments( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon );
- static pascal OSErr HandlePrintDocuments( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon );
-
- static OSErr HandleOpenDesc( AEDesc* theDesc );
- static OSErr GetDescriptorData( const AEDesc* theDesc, Ptr destPtr, Size maxSize );
-
- static OSErr GetTargetAppDesc( OSType theAppCreator, AEDesc* theTarget );
-
-
- // Globals
- extern bool gbQuit;
-
-
- OSErr InitAppleEvents ( void )
- {
- short err;
- long response;
-
- err = Gestalt( gestaltAppleEventsAttr, &response );
- if (noErr != err)
- response = 0L;
-
- if ( ! ( response & (1 << gestaltAppleEventsPresent)) )
- return gestaltUndefSelectorErr;
-
- err = AEInstallEventHandler ( kCoreEventClass, kAEOpenApplication,
- NewAEEventHandlerProc(HandleOpenApplication), 0L, false );
- if (noErr != err) goto done;
-
- err = AEInstallEventHandler ( kCoreEventClass, kAEQuitApplication,
- NewAEEventHandlerProc(HandleQuitApplication), 0L, false );
- if (noErr != err) goto done;
-
- err = AEInstallEventHandler ( kCoreEventClass, kAEOpenDocuments,
- NewAEEventHandlerProc(HandleOpenDocuments), 0L, false );
- if (noErr != err) goto done;
-
- err = AEInstallEventHandler ( kCoreEventClass, kAEPrintDocuments,
- NewAEEventHandlerProc(HandlePrintDocuments), 0L, false );
-
- done:
- return err;
- }
-
-
-
- OSErr DoAppleEvent( EventRecord *event )
- {
- short err = noErr;
-
- err = AEProcessAppleEvent ( event );
- return err;
- }
-
-
-
- static pascal OSErr HandleOpenApplication( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon )
- {
- #ifdef __MWERKS__
- #pragma unused (theAppleEvent, theReply, theRefcon )
- #endif
- // don't do anything here
- return noErr;
- }
-
-
-
- static pascal OSErr HandleQuitApplication( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon )
- {
- #ifdef __MWERKS__
- #pragma unused (theAppleEvent, theReply, theRefcon )
- #endif
-
- gbQuit = true;
- return noErr;
- }
-
-
- // If we get a folder dropped onto the application then we'll add it to our
- // list of folders to watch.
-
- static pascal OSErr HandleOpenDocuments( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon )
- {
- #ifdef __MWERKS__
- #pragma unused( theAppleEvent, theReply, theRefcon )
- #endif
-
- // do nothing here
- return noErr;
- }
-
-
- static OSErr HandleOpenDesc( AEDesc* theDesc )
- {
- #ifdef __MWERKS__
- #pragma unused(theDesc)
- #endif
-
- // do nothing here
- return noErr;
- }
-
-
- static OSErr GetDescriptorData( const AEDesc* theDesc, Ptr destPtr, Size maxSize )
- {
- Size copySize;
- OSErr err;
-
- if ( typeNull == theDesc->descriptorType || ! theDesc->dataHandle )
- return( errAENotAEDesc );
-
- copySize = GetHandleSize( (Handle)theDesc->dataHandle );
- if ( copySize <= maxSize )
- {
- HLock( (Handle)theDesc->dataHandle );
- BlockMoveData( *theDesc->dataHandle, destPtr, copySize );
- HUnlock( (Handle)theDesc->dataHandle );
- }
- else
- err = errAECorruptData;
-
-
- return noErr;
- } // GetDescriptorData
-
-
-
- static pascal OSErr HandlePrintDocuments( AppleEvent *theAppleEvent, AppleEvent *theReply, long theRefcon )
- {
- #ifdef __MWERKS__
- #pragma unused(theAppleEvent, theReply, theRefcon )
- #endif
-
- // Faceless Background Applications can't print documents
- return errAEEventNotHandled;
- }
-